package com.mibao.activity;

import java.util.regex.Pattern;

import com.mipai.R;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class SetEmailActivity extends Activity {
	private Button sureButton = null;
	private EditText email = null;
	private TextView email_tip = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.emailset);
		email = (EditText) findViewById(R.id.email_set);
		email_tip = (TextView) findViewById(R.id.email_tip);
		sureButton = (Button) findViewById(R.id.guid_sure_email);
		sureButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View view) {
				String emailStr = email.getText().toString().trim();
				boolean isEmail = this.isEmail(emailStr);
				if (isEmail) {
					Intent intent = new Intent(SetEmailActivity.this, MainActivity.class);
					startActivity(intent);
					finish();
				} else {
					email_tip.setText("格式错误！");
				}
			}

			private boolean isEmail(String emailStr) {
				Pattern pattern = Pattern.compile("^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\\.([a-zA-Z0-9_-])+)+$");
				return pattern.matcher(emailStr).matches();
			}
		});
	}
}
